
/*    This file is part of the Managarm operating system.
 *   Copyright (C) 2007, 2008, 2009  Alexander van der Grinten
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

package org.managarm.jmanavalib.core;

public class VaLiteral extends VaObject {
	// represents a null reference operand
	public static final class LitNull extends VaLiteral {
		@Override public boolean equals(Object object) {
			return object instanceof LitNull;
		}
		
		@Override public int hashCode() {
			return 0x12345678;
		}
	}
	
	// represents a boolean operand
	public static final class LitBoolean extends VaLiteral {
		public final boolean value;
		
		public LitBoolean(boolean value) {
			this.value = value;
		}
		
		@Override public int hashCode() {
			return 37 * 17 + (value ? 1 : 0);
		}
		
		@Override public boolean equals(final Object object) {
			if(object instanceof LitBoolean == false)
				return false;
			final LitBoolean other = (LitBoolean)object;
			return value == other.value;
		}
	}
	
	// represents an unsigned integer operand
	public static final class LitUInt extends VaLiteral {
		public final long value;
		
		public LitUInt(long value) {
			this.value = value;
		}
		
		@Override public int hashCode() {
			return 37 * 17 + (int)(value ^ (value >>> 32));
		}
		
		@Override public boolean equals(final Object object) {
			if(object instanceof LitUInt == false)
				return false;
			final LitUInt other = (LitUInt)object;
			return value == other.value;
		}
	}
	
	// represents a character operand
	public static final class LitChar extends VaLiteral {
		public final char value;
		
		public LitChar(char value) {
			this.value = value;
		}
		
		@Override public final int hashCode() {
			int hash = 17;
			hash = 37 * hash + value;
			return hash;
		}
		
		@Override public final boolean equals(final Object object) {
			if(object instanceof LitChar == false)
				return false;
			final LitChar other = (LitChar)object;
			return value == other.value;
		}
	}
	
	// represents a character array operand
	public static final class LitCharArray extends VaLiteral {
		private final char[] array;
		
		public LitCharArray(char[] array) {
			this.array = array.clone();
		}
		
		// returns the array size
		public final int size() {
			return array.length;
		}
		
		// returns the element at "index"
		public final char get(int index) {
			return array[index];
		}
		
		@Override public boolean equals(Object object) {
			if(object instanceof LitCharArray == false)
				return false;
			final LitCharArray other = (LitCharArray)object;
			return array.equals(other.array);
		}
		
		@Override public int hashCode() {
			return array.hashCode();
		}
	}
}
